package o;

import android.content.pm.PackageManager;
import android.text.TextUtils;
import androidx.annotation.NonNull;
import com.huawei.appgallery.packagemanager.api.bean.ManagerTask;
import java.io.File;
import java.util.regex.Pattern;
import o.cof.a;

public abstract class cpq {
    public static int ˋ(String str) {
        if (!TextUtils.isEmpty(str)) {
            String[] split = str.split(":");
            if (split.length >= 1) {
                String str2 = split[0];
                if (!TextUtils.isEmpty(str2)) {
                    if (ॱ(str2)) {
                        try {
                            return Integer.parseInt(str2);
                        } catch (NumberFormatException e) {
                            cnu.ˏ.ˎ("InstallFailedUtils", "can not parseInt:" + str2);
                        }
                    }
                    try {
                        return PackageManager.class.getDeclaredField(str2).getInt(null);
                    } catch (NoSuchFieldException e2) {
                        return cpr.ˏ(str2);
                    } catch (IllegalAccessException e3) {
                        return cpr.ˏ(str2);
                    } catch (IllegalArgumentException e4) {
                        return cpr.ˏ(str2);
                    }
                }
            }
        }
        cnu.ˏ.ˋ("InstallFailedUtils", "unstandard extraStatus:" + str);
        return -11007;
    }

    private static boolean ॱ(String str) {
        return Pattern.compile("^[-\\+]?[\\d]*$").matcher(str).matches();
    }

    public static void ˋ(@NonNull ManagerTask managerTask) {
        cnu.ˏ.ˋ("InstallFailedUtils", "delete, Apk: " + managerTask.packageName);
        File file = null;
        for (a aVar : managerTask.apkInfos) {
            File parentFile;
            File file2 = new File(aVar.ˎ);
            if (file == null) {
                parentFile = file2.getParentFile();
            } else {
                parentFile = file;
            }
            if (!file2.delete()) {
                cnu.ˏ.ˏ("InstallFailedUtils", "file delete error.");
            }
            file = parentFile;
        }
        if (file != null) {
            String[] list = file.list();
            if ((list == null || list.length == 0) && !file.delete()) {
                cnu.ˏ.ˊ("InstallFailedUtils", "delete parent failed.");
            }
        }
    }
}
